 <extend name="Public:base"/>
<block name="leftcolumn">

<div class="panel panel-info">
       <div class="panel-heading">
          <h3 class="panel-title">
             二维码扫描
          </h3>
       </div>
       <div class="panel-body">

              <div class="form-group">
                <button class="btn btn-default" id="scanQRCode0">饲料</button>
                <input type="text" id="id_securityCode_input0" class="form-control"> 
              </div>
              <div class="form-group">
                <button class="btn btn-default" id="scanQRCode1">饲料</button>
                <input type="text"id="id_securityCode_input1" class="form-control">  
              </div> 
              <button id="submit" class="btn btn-primary">提交</button>
              
       </div>
</div>
<div class="panel panel-info">
       <div class="panel-heading">
          <h3 class="panel-title">
             获取地理位置
          </h3>
       </div>
       <div class="panel-body">

              
              <div class="form-group text-center">
                 <button class="btn btn-info btn-lg" id="address">位置</button>
              </div>
              <div class="form-group">
                  <label for="">经度</label>
                  <input type="text" id="latitude" class="form-control">   
              </div>
               <div class="form-group">
                  <label for="">纬度</label>
                  <input type="text" id="longitude" class="form-control">   
              </div>
              <div class="form-group">
                  <label for="">位置经度</label>
                  <input type="text" id="accuracy" class="form-control">   
              </div>
              
              <button id="submit" class="btn btn-primary">提交</button>
       </div>
</div>
<div class="panel panel-info">
       <div class="panel-heading">
          <h3 class="panel-title">
             获取图片
          </h3>
       </div>
       <div class="panel-body">

              <div class="form-group text-center">
                 <button class="btn btn-info btn-lg" id="picture">拍照</button>
              </div>
              <div class="form-group">
                  <div id="img"></div>
              </div>
              
       </div>
</div>
</block>
<block name="rightcolumn">
  
</block>
<block name="script">

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    wx.config({
        debug: false,
        appId: '{$signPackage["appId"]}',
        timestamp: '{$signPackage["timestamp"]}',
        nonceStr: '{$signPackage["nonceStr"]}',
        signature: '{$signPackage["signature"]}',
        jsApiList: [
            'checkJsApi',
            'scanQRCode',
            'getLocation',
            'chooseImage'
        ]
    });
    wx.ready(function () {

        $("#scanQRCode0").click(function() { 

          wx.scanQRCode({ // 默认为0，扫描结果由微信处理，1则直接返回扫描结果 
                needResult : 1,
                desc : 'scanQRCode desc',
                success : function(res) { //扫码后获取结果参数赋值给Input var
                 url = res.resultStr; //商品条形码，取","后面的
                  if(url.indexOf(",")>=0){ var tempArray = url.split(','); var tempNum = tempArray[1];
                        $("#id_securityCode_input0").val(tempNum);
                    }else{
                        $("#id_securityCode_input0").val(url);
                    }
                }
            });
        });
        $("#scanQRCode1").click(function() { 
          wx.scanQRCode({ // 默认为0，扫描结果由微信处理，1则直接返回扫描结果 
                needResult : 1,
                desc : 'scanQRCode desc',
                success : function(res) { //扫码后获取结果参数赋值给Input var
                 url = res.resultStr; //商品条形码，取","后面的
                  if(url.indexOf(",")>=0){ var tempArray = url.split(','); var tempNum = tempArray[1];
                        $("#id_securityCode_input1").val(tempNum);
                    }else{
                        $("#id_securityCode_input1").val(url);
                    }
                }
            });
        });
        $("#address").click(function() { 

             wx.getLocation({
              type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
              success: function (res) {
                  var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                  var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                  var speed = res.speed; // 速度，以米/每秒计
                  var accuracy = res.accuracy; // 位置精度
                  $('#latitude').val(latitude);
                  $('#longitude').val(longitude);
                  $('#accuracy').val(accuracy);
              }
            });
        });
        $("#picture").click(function() { 

             wx.chooseImage({
                count: 1, // 默认9
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {
                    var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                    $.each( res.localIds, function(i, n){
                            $("#img").append('<img src="'+n+'" /> <br />');
                    });

                }
            });
        });
     });
</script>
</block>